package com.jing.shop.controller;

import com.github.pagehelper.PageInfo;
import com.jing.common.core.domain.R;
import com.jing.shop.domain.dto.ProductAttributeDTO;
import com.jing.shop.domain.vo.ProductAttributeVO;
import com.jing.shop.service.ProductAttributeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "商品属性管理")
@RestController
@RequestMapping("/attribute")
public class ProductAttributeController {

    private static final Logger log = LoggerFactory.getLogger(ProductAttributeController.class);

    @Autowired
    private ProductAttributeService productAttributeService;

    @ApiModelProperty("商品属性列表")
    @PostMapping("/page")
    public R findAttributeList(@RequestBody ProductAttributeDTO productAttributeDTO){
        PageInfo<ProductAttributeVO> attributeList = productAttributeService.findAttributeList(productAttributeDTO);
        return R.ok(attributeList,"属性列表");
    }

    @ApiModelProperty("商品参数")
    @PostMapping("/findAttrList")
    public R findAttrList(@RequestBody ProductAttributeDTO productAttributeDTO){
        PageInfo<ProductAttributeVO> attributeList = productAttributeService.findAttrList(productAttributeDTO);
        return R.ok(attributeList,"参数列表");
    }

    @ApiModelProperty("/添加属性")
    @PostMapping("/add")
    public R addAttribute(@RequestBody ProductAttributeDTO productAttributeDTO){
        productAttributeService.addAttribute(productAttributeDTO);
        return R.ok("添加成功");
    }

    @ApiModelProperty("/修改属性")
    @PostMapping("/update")
    public R updateAttribute(@RequestBody ProductAttributeDTO productAttributeDTO){
        productAttributeService.updateAttribute(productAttributeDTO);
        return R.ok("修改成功");
    }

    @ApiModelProperty("/删除属性")
    @PostMapping("/del/Ids")
    public R delAttribute(@PathVariable Integer[] Ids){
        productAttributeService.delAttribute(Ids);
        return R.ok("删除成功");
    }

}
